package com.cf.base.leak;

import android.os.SystemClock;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;

/**
 * @author yangji
 */
public class ObjectReference extends WeakReference<Object> {

    private final String key;
    private final long time;
    private long lastTime;
    private String className;
    private boolean isLeak = false;

    public ObjectReference(String key, Object referent, ReferenceQueue<? super Object> q) {
        super(referent, q);
        if (referent != null) {
            className = referent.getClass().getName();
        }
        this.time = SystemClock.uptimeMillis();
        this.key = key;
    }

    public String getKey() {
        return key;
    }

    public void updateLastTime() {
        lastTime = SystemClock.uptimeMillis();
    }

    public void leak() {
        updateLastTime();
        isLeak = true;
    }
}
